package wnhz.com.business.freeshop.fragment;

import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.base.MyBaseActivity;
import wnhz.com.business.base.MyBaseFragment;
import wnhz.com.business.freeshop.activity.fristfree.CityChooseActivity;
import wnhz.com.business.freeshop.activity.fristfree.FreeGoodsDetailsActivity;
import wnhz.com.business.freeshop.activity.fristfree.ScanningAvtivity;
import wnhz.com.business.freeshop.activity.fristfree.SearchActivity;

/**
 * Created by Administrator on 2017/9/21 0021.
 */

public class FristFragment extends MyBaseFragment {
    Unbinder unbinder;
    @BindView(R.id.tv_tt)
    TextView tvTt;
    @BindView(R.id.iv_actionbar_left)
    ImageView ivActionbarLeft;
    @BindView(R.id.tv_place)
    TextView tvPlace;
    @BindView(R.id.lay_actionbar_left)
    RelativeLayout layActionbarLeft;
    @BindView(R.id.tv_title_f)
    TextView tvTitleF;
    @BindView(R.id.iv_seach_f)
    ImageView ivSeachF;
    @BindView(R.id.iv_scanning_f)
    ImageView ivScanningF;
    @BindView(R.id.tv_fruit)
    TextView tvFruit;
    @BindView(R.id.tv_doctor)
    TextView tvDoctor;
    @BindView(R.id.tv_snacks)
    TextView tvSnacks;
    @BindView(R.id.tv_flowers)
    TextView tvFlowers;
    @BindView(R.id.tv_luxury)
    TextView tvLuxury;
    @BindView(R.id.ll_hot)
    LinearLayout llHot;
    @BindView(R.id.recycler_hotdata)
    RecyclerView recyclerHotdata;
    @BindView(R.id.ll_exchange)
    LinearLayout llExchange;
    @BindView(R.id.recycler_exchange)
    RecyclerView recyclerExchange;
    @BindView(R.id.tv_rebatehome_guess)
    TextView tvRebatehomeGuess;
    @BindView(R.id.recycler_daa)
    RecyclerView recyclerDaa;
    private MyBaseActivity activity;

    private List<String> itemddd = new ArrayList<>();

    @Override
    protected void handleMsg(Message msg) {

    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_free_frist, container, false);

        return view;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        activity = (MyBaseActivity) getActivity();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            //透明导航栏
//            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            //改变状态栏颜色
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            tvTt.setVisibility(View.VISIBLE);
            //获取到状态栏的高度
            int statusHeight = getStatusBarHeight();
            //动态的设置隐藏布局的高度
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tvTt.getLayoutParams();
            params.height = statusHeight;
            tvTt.setLayoutParams(params);
        }

        initview();
        setrecyclerhot();
        setrecyclerexchange();
        setrecyclerdaa();
        return rootView;
    }

    private void initview() {

        recyclerHotdata.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        recyclerExchange.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recyclerDaa.setLayoutManager(new GridLayoutManager(getContext(), 2, LinearLayoutManager.VERTICAL, false));
        itemddd.clear();
        for (int i = 0; i < 6; i++) {
            itemddd.add("a" + i);
        }
    }


    /**
     * 热卖
     */
    private void setrecyclerhot() {
        recyclerHotdata.setAdapter(new BaseRVAdapter(getContext(), itemddd) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_hot_f;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getView(R.id.ll_itemm).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(FreeGoodsDetailsActivity.createIntent(getContext(), "", "", ""));
                    }
                });

            }

        });
    }

    /**
     * 猜你喜欢
     */
    private void setrecyclerdaa() {
        recyclerDaa.setAdapter(new BaseRVAdapter(getContext(), itemddd) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_hot_f;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getView(R.id.ll_itemm).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(FreeGoodsDetailsActivity.createIntent(getContext(), "", "", ""));
                    }
                });
            }
        });
    }

    /**
     * 兑换分区
     */
    private void setrecyclerexchange() {
        recyclerExchange.setAdapter(new BaseRVAdapter(getContext(), itemddd) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_daa_f;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getView(R.id.ll_itemmm).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(FreeGoodsDetailsActivity.createIntent(getContext(), "", "", ""));
                    }
                });
            }

        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.lay_actionbar_left, R.id.iv_seach_f, R.id.iv_scanning_f})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lay_actionbar_left://定位
                startActivity(CityChooseActivity.createIntent(getContext()));
                break;
            case R.id.iv_seach_f://搜索
                startActivity(SearchActivity.createIntent(getContext()));
                break;
            case R.id.iv_scanning_f://扫描我二维码
                startActivity(ScanningAvtivity.createIntent(getContext()));
                break;
        }
    }
}
